﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.ComponentModel;
using System.Collections.Specialized;


namespace baseClass.Controls
{
    public class gridSyslog : common.controls.baseDataGridView
    {
        public enum ColumnNames
        {
            id, onDate, message , source, detailBtn
        };

        public gridSyslog()
        {

        }

        private baseClass.Forms.syslogDetail myViewLogDetailForm = null;
        private void ShowDetail()
        {
            if (this.myViewLogDetailForm == null || this.myViewLogDetailForm.IsDisposed) 
                this.myViewLogDetailForm = new baseClass.Forms.syslogDetail();
            this.myViewLogDetailForm.SetDataSource(this.myEditDataSource);
            this.myViewLogDetailForm.ShowDialog();
        }

        protected override void OnCellClick(DataGridViewCellEventArgs e)
        {
            base.OnCellClick(e);
            try
            {
                if (this.CurrentRow == null) return;
                if (this.Columns[e.ColumnIndex].Name != baseClass.Controls.gridSyslog.ColumnNames.detailBtn.ToString()) return;
                ShowDetail();
            }
            catch (Exception er)
            {
                this.ErrorHandler(this, er);
            }
        }
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);
            try
            {
                if (this.CurrentRow == null) return;
                ShowDetail();
            }
            catch (Exception er)
            {
                this.ErrorHandler(this, er);
            }
        }

        public override void Init()
        {
            base.Init();
            data.systemDS.sysLogDataTable dummyTbl = new data.systemDS.sysLogDataTable();
            
            // 
            // id
            // 
            common.controls.DataGridViewTextBoxColumnExt id = new common.controls.DataGridViewTextBoxColumnExt();
            id.DataPropertyName = dummyTbl.idColumn.ColumnName;
            id.HeaderText = "#";
            id.Name = ColumnNames.id.ToString();
            id.Width = 50;

            // 
            // onDate
            // 
            common.controls.DataGridViewTextBoxColumnExt onDate = new common.controls.DataGridViewTextBoxColumnExt();
            onDate.DataPropertyName = dummyTbl.onDateColumn.ColumnName;
            onDate.HeaderText = "Ngày/Giờ";
            onDate.Name = ColumnNames.onDate.ToString();
            onDate.Width = 150;
            onDate.DefaultCellStyle.Format = "g";

            // 
            // message
            // 
            common.controls.DataGridViewTextBoxColumnExt message = new common.controls.DataGridViewTextBoxColumnExt();
            message.DataPropertyName = dummyTbl.messageColumn.ColumnName;
            message.HeaderText = "Mô tả";
            message.Name = ColumnNames.message.ToString();
            message.Width = 400;

            // 
            // source
            // 
            common.controls.DataGridViewTextBoxColumnExt source = new common.controls.DataGridViewTextBoxColumnExt();
            source.DataPropertyName = dummyTbl.sourceColumn.ColumnName;
            source.HeaderText = "Nguồn";
            source.Name = ColumnNames.source.ToString();
            source.Width = 100;

            // 
            // detailBtn
            // 
            common.controls.gridViewImageColumn detailBtn = new common.controls.gridViewImageColumn();
            detailBtn.HeaderText = "";
            detailBtn.Name = ColumnNames.detailBtn.ToString();
            detailBtn.myImageType = common.controls.ImageTypes.Info;

            // 
            // detailGrid
            // 
            this.Columns.Clear();
            this.Columns.AddRange(new DataGridViewColumn[] { id, onDate,  message, source, detailBtn });
            //this.DisableReadOnlyColumns();
            this.myAutoFitColumn = message.Name;
            this.AutoFit();
        }
    }
}
